<?php

declare(strict_types=1);

namespace App\Controller\Admin;

use App\Controller\BaseController;
use App\Model\Notify;
use App\Model\NotifyClassify;
use Hyperf\HttpServer\Annotation\AutoController;

/**
 * @AutoController()
 */
class NotifyController extends BaseController
{
    //  获取分类
    public function gets()
    {
        $data = NotifyClassify::all();
        return $this->success($data);
    }

    public function lists()
    {
        $data = Notify::with('notifyClassify')
            ->whereHas('notifyClassify',function ($query){
               $query->select('id','name');
            })
            ->paginate($this->request->limit);


        return $this->success(['items' => $data->items(),'total' => $data->total()]);
    }



    public function store()
    {
        $post = $this->request->inputs(['title','desc','path','pid','contents']);

        Notify::create($post);

        return $this->message('添加成功');
    }

    public function update()
    {
        $post = $this->request->inputs(['title','desc','path','pid','contents']);

        Notify::where('id',$this->request->input('id'))->update($post);

        return $this->message('更新成功');
    }

    public function delete()
    {
        $id = $this->request->input('id');

        Notify::where('id',$id)->delete();

        return $this->message('删除成功');
    }
}
